package com.da.javatest.leetCode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chenlida
 * @date 2019/1/5 15:02
 * @description
 */
public class Code206 {
    private List<Integer> list = new ArrayList<>();

    public ListNode reverseList(ListNode head) {
        getMax(head);
        setNode(head, list, list.size() - 1);
        return head;
    }

    private void getMax(ListNode node) {
        if (node != null) {
            list.add(node.val);
            getMax(node.next);
        }
    }

    private void setNode(ListNode node, List<Integer> list, int i) {
        if (node != null) {
            node.val = list.get(i);
            setNode(node.next, list, i -= 1);
        }
    }
}
